package com.yhy.server.controller;

import com.yhy.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;
import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {


    @Autowired
    private MessageService messageService;

    /**
     * 公告查询
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize){
        return messageService.announcements(page,pagesize);
    }

    /**
     * 联系人添加
     *
     * 接口路径：POST/messages/contacts
     *
     * 请求参数:Body
     *      userId: 用户id
     *
     * 返回值: null
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        Integer id = (Integer) map.get("userId");
        Long friendUserId = Long.valueOf(id);
        return messageService.addContacts(friendUserId);
    }

    /**
     * 联系人列表
     *
     * 接口路径：GET /messages/contacts
     *
     * 请求参数: Query:
     *      page: 页数
     *      pagesize: 页尺寸
     *      keyword: 关键字
     *
     * 返回值: PageResult<ContactVo>
     *
     */
    @GetMapping("/contacts")
    public ResponseEntity showContacts(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize){
        return messageService.queryContactsList(page,pagesize);
    }

    /**
     * 查看点赞列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        return messageService.likes(page,pagesize,1);
    }

    /**
     * 查看喜欢列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        return messageService.likes(page,pagesize,3);
    }

    /**
     * 查看评论列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        return messageService.likes(page,pagesize,2);
    }
}
